$(function () {
    //款项类型
    $("#form_fksh").find("[idVal='fksh_kxyt_id']").sjzdcombobox("kxyt");

    //票据类型
    $("#form_fksh").find("[idVal='fksh_pjlx_id']").sjzdcombobox("pjlx");

    //回款类型
    $("#form_fksh").find("[idVal='fksh_hklx_id']").sjzdcombobox("hklx");



    $(function(){


        $("#fksh_gldw_id").combobox({
                url:$.webPath() + "/organ/qyjg/findAllKsyJkdByNbgsId?nbgsId="+ $("#fksh_sbgs_id").val()
        });
        //

        //内部付款
        $("[name='fkshNbfk']").change(function () {
            var type = $(this).val();
            var newValue = $("#fksh_sbgs_id").val();
//            var newValue = $("#fksh_sbgs_id").combobox("getValue");
            if (type == 1) {
                $("#fksh_gldw_id").combobox("reload", $.webPath() + "/organ/qyjg/findAllKsyJkdByNbgsId?nbgsId=" + newValue);
                $("#fksh_gldw_id").combobox("clear");
            } else {
                $("#fksh_gldw_id").combobox("reload", $.webPath() + "/organ/gsjg/gsjgMcList?type=1" );
                $("#fksh_gldw_id").combobox("clear");
            }
        });

    });

    var fkshId = $("#fksh_id").val();
    if(fkshId==""){
        fkshId = 0;
    }
   //电子借款单
    $("#jkd_grid").edatagrid({
        url:$.webPath() + "/sfgl/fkshmx/fkshmxList?fkshId="+fkshId,
        fitColumns: false,
        singleSelect: true,
        checkOnSelect: false,
        selectOnCheck: false,
        fit:false,
        width:1000,
        height:230,
        rownumbers: true,
        frozenColumns: [
            [
                {field:'id', title:'ID', hidden:true},
                {field:'jkd.id', title:'JkdIds', hidden:true},
                {field:'jkd_id', title:'JkdId', hidden:true},
                {field:'jkd.jkdbm', title:'单号', width:100,align: 'center'},
                {field:'jkd.zfsj', title:'支付日期', width:80,align: 'center'},
                {field:'jkd.gys.qc', title:'收款单位', width:100,align: 'center'},
                {field:'jkd.zfkx', title:'支付款项', width:70,align: 'center'},
                {field:'jkd.zffs.z', title:'支付方式', width:50,align: 'center'},
                {field:'jkd.cght.htbm', title:'合同单号', width:100,align: 'center'}
            ]
        ],
        columns: [
            [
                {field:'jkd.zfje', title:'申请金额(元)', width:150,
                    formatter:function(value){
                        var sl = formatJe2(value,",");
                        return sl;
                    },align: 'right'},
                {field:'fkrq', title:'付款日期', width:70,align: 'center'},
                {field: 'jkd.yfje', title: '已付金额(元)', width: 150,
                    formatter:function(value){
                        var sl = formatJe2(value,",");
                        return sl;
                    },align: 'right'},
                {field: 'bcfkmx', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}},title: '本次付款(元)', width:150,
                    formatter:function(value){
                        var sl = formatJe2(value,",");
                        return sl;
                    },align: 'right'}
            ]
        ],
        onSelect:function(rowIndex,rowData){
            $('#jkd_grid').edatagrid('editRow',rowIndex);
        }
    })

    //搜索电子借款单
    $("#btn_jkd_add").click(function () {
        var gldwId = $('#fksh_gldw_id').combotree('getValue');
        if(gldwId){
            searcJkdhwindow(grid_jkd_searchWindowOKbtnHandler);
        }   else {
            $.messager.alert('提示','请先选择供应商!', "info");
        }

    });
    //删除电子借款单的按钮触发
    $("#btn_jkd_del").click(function () {
        var jkdRow = $('#jkd_grid').datagrid('getSelected');
        var jkdIndex = $('#jkd_grid').datagrid('getRowIndex',jkdRow);
        if(jkdRow){
            $('#jkd_grid').edatagrid('deleteRow',jkdIndex);
        } else {
            $.messager.alert('提示','请选择要删除的电子借款单!');
        }
    });
});

//查询电子借款单确定按钮回调函数
function grid_jkd_searchWindowOKbtnHandler(data) {
    $.each(data, function () {
        $("#jkd_grid").edatagrid('appendRow', {
            'jkd.id': this.id,
            'jkd_id': this.id,
            'jkd.jkdbm': this.jkdbm,
            'jkd.zfsj': this.zfsj,
            'jkd.gys.qc':this.gys_qc,
            'jkd.zfkx': this.zfkx,
            'jkd.zffs.z': this.zffs_z,
            'jkd.cght.htbm': this.cght_htbm,
            'jkd.zfje': this.zfje,
            'jkd.yfje': this.yfje
        });
    });
}